def retrieveplan():
    import urllib.request
    from urllib.error import URLError, HTTPError
    import datetime
    import os
    
    # Build a dictionary of german localized names for months so that the
    # program will also work on non german systems
    months = ["Januar",
              "Februar",
              "Maerz",
              "April",
              "Mai",
              "Juni",
              "Juli",
              "August",
              "September",
              "Oktober",
              "November",
              "Dezember"]
    lastmodified = ""

    ### Step 1 - Read last modified date
    # Try opening the file and reading the last modified date 
    # throws an exception if it doesn't exist meaning that the user
    # deleted it or this is the first start
    try:
        with open(os.path.join(os.getcwd(), "lastmodified.txt"), "r") as f:
            lastmodified = f.read()
    except IOError as e:
        # Set a way back date to ensure the file gets downloaded
        lastmodified = "Thu, 01 Jan 1970 00:00:00 GMT"

    ### Step 2 - Build the correct URL using the systems date
    # Get the german localized month of the year
    now = months[datetime.datetime.now().month-1]

    # Build basic URL
    url = "https://89.221.15.138/schichtpl%C3%A4ne/2012/Schichtplanmatrix_" \
          + now \
          + ".ods"

    # Create password-manager and set Username/Password
    password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
    password_mgr.add_password("login required for schichtplaene", url,\
                              "markus", "goiseifa,")

    # Create handler that can be used by an opener
    handler = urllib.request.HTTPBasicAuthHandler(password_mgr)

    # Create a new opener and replace default opener
    opener = urllib.request.build_opener(handler)
    urllib.request.install_opener(opener)

    # Create a request with the If-Modified-Since header set
    req = urllib.request.Request(url, data=None, \
                                 headers={"If-Modified-Since": lastmodified})


    ### Step 3 - Contact the server with our custom tailored request and react on its response
    # Try invoking the opener and fetch the data - urllib raises an exception if the return
    # code is not 200 OK or 301, 302 temporary/permanent redirect, even if the desired
    # behavior is to get another return code
    print("Suche nach neuer Version...")
    try:
        res = urllib.request.urlopen(req)
    except HTTPError as e:
        # The server sent a status other than 200, 301 or 302 (see above)
        if e.code == 304:
            print("Keine Änderungen, der Schichtplan ist aktuell.")
        else:
            print("Der Server konnte die Anfrage nicht verarbeiten.")
            print("HTTP Fehlercode: ", e.code)
    except URLError as e:
        # The URL couldn't be retrieved - maybe a mouse chewed on your network cable?
        print("Netzwerkfehler... :(")
        print(e.reason)
    else:
        print("Neue Version gefunden!")
        print("Schreibe Datei...")
        with open(os.path.join(os.getcwd(), "Schichtplanmatrix_" + now + \
                               ".ods"), "wb") as local_file:
            local_file.write(res.read())
        with open(os.path.join(os.getcwd(), "lastmodified.txt"), "w") as f:
            f.write(res.headers["Last-Modified"])
        print("Fertig!")